<template>
  <!--添加或者修改数据的弹窗-->
  <el-dialog
    :title="workForm._id ? '编辑' : '添加'"
    :visible.sync="popIsShow"
    width="600px">
    <el-form
      :model="workForm"
      label-width="100px">

      <!--公司名称-->
      <el-form-item
        :rules="[{ required: true, message: '公司名称不能为空'}]"
        prop="name"
        label="公司名称">
        <el-input
          v-model="workForm.name"
          clearable
          placeholder="请输入"/>
      </el-form-item>

      <!--公司详情-->
      <el-form-item label="公司详情">
        <el-input
          v-model="workForm.detail"
          type="textarea"
          clearable
          placeholder="请输入"/>
      </el-form-item>

      <!--公司职责-->
      <el-form-item label="公司职责">
        <el-input
          v-model="workForm.obligation"
          clearable
          placeholder="请输入"/>
      </el-form-item>

      <!--公司官网-->
      <el-form-item label="公司官网">
        <el-input
          v-model="workForm.url"
          clearable
          placeholder="请输入"/>
      </el-form-item>

      <!--公司照片-->
      <el-form-item
        label="公司照片"
        v-if="popIsShow">
        <w-image-up
          ref="UP_IMAGE"
          :souce-url="workForm.icon"/>
      </el-form-item>

      <!--任职时间-->
      <el-form-item
        label="任职时间"
        class="w-clear-frome-bottom">
        <el-col :span="11">
          <el-date-picker
            v-model="workForm.startTime"
            type="date"
            placeholder="开始时间"
            style="width: 100%;"/>
        </el-col>
        <el-col
          :span="2"
          class="line w-text-center">-</el-col>
        <el-col :span="11">
          <el-date-picker
            v-model="workForm.endTime"
            type="date"
            placeholder="结束时间"
            style="width: 100%;"/>
        </el-col>
      </el-form-item>
    </el-form>
    <div
      slot="footer"
      class="dialog-footer">
      <el-button
        size="mini"
        @click="popIsShow = false">取 消</el-button>
      <el-button
        :disabled="!workForm.name"
        size="mini"
        type="primary"
        @click="okBtnClick">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import WorkModel from '@/models/web/WorkModel'
import WImageUp from '@/components/global/imageUp/oss'
export default {
  name: 'AdminWebExperience',
  components: {
    WImageUp
  },
  data() {
    return {
      /**
       * 模型数据
       */
      workForm: new WorkModel(),
      /**
       * 是否显示弹窗
       */
      popIsShow: false
    }
  },
  methods: {
    /**
     * 显示弹窗
     * @param model
     */
    show(model = {}) {
      this.workForm = new WorkModel()
      Object.assign(this.workForm, model)
      this.popIsShow = true
    },
    /**
     * 确认按钮点击
     * @returns {Promise<void>}
     */
    async okBtnClick() {
      try {
        this.workForm.icon = await this.$refs['UP_IMAGE'].upImage()
        this.workForm.addOrUpdate().then(() => {
          this.popIsShow = false
          this.$emit('reload')
        }).catch(() => {})
      } catch (e) {
        this.$w_popview.msgError(e.msg)
      }
    }
  }
}
</script>

<style scoped>

</style>
